package com.daodaoclub.payment.wxpay.impl;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URL;

import com.daodaoclub.payment.wxpay.sdk.IWXPayDomain;
import com.daodaoclub.payment.wxpay.sdk.WXPayConfig;


public class CostinWXPayConfig extends WXPayConfig{
	
    private byte[] certData;
    private static CostinWXPayConfig INSTANCE;

    private CostinWXPayConfig() throws Exception{
        //String certPath = "/wxpay/apiclient_cert.p12";
    	URL resource = Object.class.getResource("/wxpay/apiclient_cert.p12");
        File file = new File(resource.getPath());
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }

    public static CostinWXPayConfig getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (CostinWXPayConfig.class) {
                if (INSTANCE == null) {
                    INSTANCE = new CostinWXPayConfig();
                }
            }
        }
        return INSTANCE;
    }
  
    public String getAppID() {
        return "wxafc30e64d9a902a5";
    }

    public String getMchID() {
        return "1489449802";
    }

    public String getKey() {
        return "2016daodaoclub0503linkenpark0601";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    public IWXPayDomain getWXPayDomain() {
        return CostinWXPayDomain.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    public int getReportWorkerNum() {
        return 1;
    }

    public int getReportBatchSize() {
        return 2;
    }
}
